package org.example.dynamic.util;


/**
 * @description 基础异常
 * @version 1.0.0
 */
public class BaseException extends RuntimeException {

    private static final long serialVersionUID = 1L;

    /**
     * 所属模块
     */
    private String module;

    /**
     * 错误码
     */
    private Integer code = 401;

    /**
     * 错误码对应的参数
     */
    private transient Object[] args;

    /**
     * 错误消息
     */
    private String message = "系统错误!";

    public BaseException(String module, Integer code, Object[] args, String message) {
        this.module = module;
        this.code = code;
        this.args = args;
        this.message = message;
    }

    public BaseException(String module, Integer code, Object[] args) {
        this(module, code, args, null);
    }

    public BaseException(String module, String message) {
        this(module, null, null, message);
    }

    public BaseException(Integer code, Object[] args) {
        this(null, code, args, null);
    }

    public BaseException(ResultCode status) {
        this(null, status.getCode(), null, status.getMsg());
    }

    public BaseException(String message) {
        this(null, ResultCode.BAD_PARAMETER.getCode(), null, message);
    }

    public Integer getCode() {
        return code;
    }

    @Override
    public String getMessage() {
        return message;
    }
}
